num = int(input())
if num % 1 > 0 or num < 1000 or num > 9999:
    print('0')
    exit()
num = str(num)
slices = [int(num[0:2]), int(num[1:3]), int(num[2:4]),
          int(num[0:3]), int(num[1:4]),
          int(num[0:4])]
num = int(num)
answer = 0
for slice in slices:
    prime = True
    for div in range(2, int(slice**0.5)+1):
        if slice % div == 0:
            prime = False
            break
    if prime:
        answer = max(answer, slice)
print(answer)
